/*
 Xern Entity Relocation Network
 Copyright (C) 2010-2011 Ronie Salgado <roniesalg@gmail.com>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
*/

#ifndef XERN_GEOMETRY_HPP
#define XERN_GEOMETRY_HPP

#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <OgreRoot.h>
#include "Xern/IGeometry.hpp"
#include "IOgreObject.hpp"

namespace XernOgre
{
	using namespace Xern;

	class OgreRenderer;
	class Geometry: public virtual IGeometry,
		public boost::enable_shared_from_this<Geometry>
	{
	public:
		Geometry(boost::shared_ptr<OgreRenderer> renderer,
				Ogre::SceneManager *scene, Ogre::MeshPtr mesh);
		~Geometry();

		Ogre::MeshPtr GetMesh() const;

		virtual ResourceFlags GetFlags() const;
		virtual void UpdateState(boost::shared_ptr<IDataFilter> stateData);

		virtual const uuid &GetId() const;
		virtual void SetId(const uuid &id);

		virtual void SetMaterial(const std::string &name);
		virtual void SetMaterial(boost::shared_ptr<IMaterial> material);
		boost::shared_ptr<IMaterial> GetMaterial() const;
		const std::string &GetMaterialName() const;

		virtual AABox GetBoundingBox() const;
		virtual void SetBoundingBox(const AABox &box);

		virtual boost::shared_ptr<IGeometryInstance> CreateInstance() const;

		virtual void UploadVertices(int buffer, size_t len, const void *data);

		void SetShadowCasting(bool shadow);
		bool GetShadowCasting() const;

	protected:
		uuid id;
		boost::shared_ptr<OgreRenderer> renderer;
		Ogre::SceneManager *scene;
		Ogre::MeshPtr mesh;
		std::string materialName;
		boost::shared_ptr<IMaterial> material;
		bool castShadow;
	};
}

#endif //XERN_GEOMETRY_HPP
